package com.hotel.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 菜单表
 * </p>
 *
 * @author XiaoGe
 * @since 2022-05-28
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("tb_menu")
@ToString
public class Menu extends Model<Menu> {

    /**
     * 菜单/按钮ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 上级菜单ID
     */
    @TableField("parent_id")
    private Long parentId;

    /**
     * 菜单/按钮名称
     */
    @TableField("menu_name")
    private String menuName;

    /**
     * 菜单URL
     */
    @TableField("url")
    private String url;

    /**
     * 权限标识
     */
    @TableField("perms")
    private String perms;

    /**
     * 图标
     */
    @TableField("icon")
    private String icon;

    /**
     * 类型 0菜单 1按钮
     */
    @TableField("type")
    private Integer type;

    /**
     * 排序
     */
    @TableField("order_num")
    private Long orderNum;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 修改时间
     */
    @TableField("modified_time")
    private Date modifiedTime;

    /**
     * 0：不可用，1：可用
     */
    @TableField("available")
    private Integer available;

    /**
     * 0:不展开，1：展开
     */
    @TableField("open")
    private Integer open;

    /**
     * 功能描述: <子菜单>
     * 〈Unknown column 'children' in 'field list'〉
     * @Param:
     * @Return:
     * @Author: Mr.Nie
     * @Date: 2022/5/23 9:42
     */
    @TableField(exist = false)  //说明这个属性不是数据库中的列名
    private List<Menu> children;


    @Override
    public Serializable pkVal() {
        return this.id;
    }

    /*
     * 排序,根据order排序
     */
    public static Comparator<Menu> order(){
        Comparator<Menu> comparator = (o1, o2) -> {
            if(o1.getOrderNum() != o2.getOrderNum()){
                return (int) (o1.getOrderNum() - o2.getOrderNum());
            }
            return 0;
        };
        return comparator;
    }

}
